//
//  DesCollectVC.m
//  HappyTrip
//
//  Created by yuxuesong on 15-4-1.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "DesCollectVC.h"
#import "DesDataObj.h"
#import "DestinationPlaceViewController.h"
#import "DesCollectTVC.h"
#import "DestinationDetailObject.h"

//推荐类收藏
#import "RecView.h"
#import "DateBaseHandler.h"
//目的地类收藏
#import "DesView.h"
//附近类收藏
#import "NeaView.h"

//happy数据库相关
#import "HappyDatabase.h"

#define COLLECTIdentifier @"desCollectCellReuse"

@interface DesCollectVC ()

@property (nonatomic, retain) UITableView *tableView;

@property (nonatomic, retain)UISegmentedControl *seg;

@property (nonatomic, retain)RecView *MyRecView;
@property (nonatomic, retain)DesView *MyDesView;
@property (nonatomic, retain)NeaView *MyNeaView;

@end

@implementation DesCollectVC

- (void)dealloc
{
    [_MyRecView release];
    [_MyDesView release];
    [_MyNeaView release];
    [_seg release];
    [_collectArr release];
    [_tableView release];
    [_nameLabel release];
    [super dealloc];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.view.backgroundColor = [UIColor colorFromHexCode:@"#F5FFFA"];
    
    [self.MyNeaView.tableView reloadData];
    [self.MyDesView.tableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"我的收藏";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"iconfont-fanhui.png"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonItemAction:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];

    //happy数据库相关
    HappyDatabase *happyDb = [HappyDatabase shareInstance];
    [happyDb openDB];
    [happyDb createTable];
    
    [[DateBaseHandler shareInstance] openDB];

    [[DesDataObj shareInstance] openHappyTrip];
    
    self.seg = [[UISegmentedControl alloc] initWithItems:@[@"推荐", @"目的地", @"附近"]];
    self.seg.frame = CGRectMake(0, 0, VIEW_WIDTH, 35);
    self.seg.tintColor = [UIColor blueColor];
    self.seg.selectedSegmentIndex = 0;//设置默认分段
    [self.seg addTarget:self action:@selector(segAction:) forControlEvents:UIControlEventValueChanged];
    [self segAction:self.seg];//默认点击一下,初始化的时候调用它的方法
    [self.view addSubview:_seg];
    [_seg release];
 
    //加入三个子视图,显示三类收藏
    self.MyNeaView = [[NeaView alloc] initWithFrame:CGRectMake(0, 35, VIEW_WIDTH, VIEW_HEIGHT - 35)];
    self.MyNeaView.target = self.navigationController;
    [self.view addSubview:_MyNeaView];// 蓝
    
    
    self.MyDesView = [[DesView alloc] initWithFrame:CGRectMake(0, 35, VIEW_WIDTH, VIEW_HEIGHT - 35)];
    self.MyDesView.target = self.navigationController;
    [self.view addSubview:_MyDesView];// 黄
    
    
    self.MyRecView = [[RecView alloc] initWithFrame:CGRectMake(0, 35, VIEW_WIDTH, VIEW_HEIGHT - 35)];
    self.MyRecView.target = self.navigationController;
    [self.view addSubview:_MyRecView];// 红

}


- (void)segAction:(UISegmentedControl *)seg
{
    if (self.seg.selectedSegmentIndex == 0) {
    
        [self.view bringSubviewToFront:_MyRecView];
        NSLog(@"在分段0中");
    }else if (self.seg.selectedSegmentIndex == 1){
    
        [self.view bringSubviewToFront:_MyDesView];
        NSLog(@"在分段1中");
    }else{
     
        [self.view bringSubviewToFront:_MyNeaView];
        NSLog(@"在分段2中");
    }
}

#pragma mark - 左侧返回按钮
- (void)leftBarButtonItemAction:(UIBarButtonItem *)button
{
    [self.navigationController popViewControllerAnimated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
